import assert from 'assert';

// 创建调用跟踪器。
const tracker = new assert.CallTracker();

function func() {
	console.log(11);
}

// 返回封装 func() 的函数，其必须在 tracker.verify() 之前调用准确次数。
const callsfunc = tracker.calls(func, 2);

callsfunc();

// 调用 tracker.verify() 并验证是否所有 tracker.calls() 函数都已被准确调用。
process.on('exit', () => {
	tracker.verify();
});
console.log(tracker.report());
/*
[
  {
    message: 'Expected the func function to be executed 2 time(s) but was executed 1 time(s).',
    actual: 1,
    expected: 2,
    operator: 'func',
    stack: Error
        at CallTracker.calls (internal/assert/calltracker.js:43:19)
        at file:///E:/%E5%89%8D%E7%AB%AF%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB/04_node/11assert/app01.js:11:27
        at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
        at async Loader.import (internal/modules/esm/loader.js:166:24)
        at async Object.loadESM (internal/process/esm_loader.js:68:5)
  }
]
*/